﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CJJCH.Web
{
    public partial class TeachList : System.Web.UI.Page
    {
        CJJCH.BLL.T_NET_MenuSecond bll_Second = new BLL.T_NET_MenuSecond();
        CJJCH.BLL.T_NET_News bll_News = new BLL.T_NET_News();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitRepater();

            }
        }
        private void InitRepater()
        {

            if (Request.QueryString["Sid"] != "" && LTP.Common.CheckInput.CheckDigit(Request.QueryString["Sid"]))
            {
                lblSID.Text = Request.QueryString["Sid"].ToString();

            }
            else
            {
                lblSID.Text = "3";
            }
            if (!string.IsNullOrEmpty(Request.QueryString["name"]))
            {
                lblMenu.Text = LTP.Common.StringClass.EncodeStr(Request.QueryString["name"].Trim());

            }
            else
            {
                lblMenu.Text = "公益讲座";
            }
            if (!string.IsNullOrEmpty(Request.QueryString["HaveChild"]))
            {
                if (Request.QueryString["HaveChild"] == "False")
                {
                    lblHaveChild.Text = "False";
                }
                else
                {
                    lblHaveChild.Text = "True";
                }
            }
            if (!string.IsNullOrEmpty(Request.QueryString["MID"]) && LTP.Common.CheckInput.CheckDigit(Request.QueryString["MID"]))
            {
                lblMID.Text = Request.QueryString["MID"].ToString();
            }
            else
            {
                lblHaveChild.Text = "";
            }
            if (!string.IsNullOrEmpty(Request.QueryString["KeyWord"]))
            {
                lblKeyWord.Text = LTP.Common.StringClass.EncodeUrl(Request.QueryString["KeyWord"].Trim());
            }
            if (!string.IsNullOrEmpty(Request.QueryString["KeyType"]) && LTP.Common.CheckInput.CheckDigit(Request.QueryString["KeyType"].Trim()))
            {
                lblKeyType.Text = LTP.Common.StringClass.EncodeUrl(Request.QueryString["keyType"].Trim());
            }
            if (Request.QueryString["curpage"] != null && LTP.Common.CheckInput.CheckDigit(Request.QueryString["curpage"].Trim()))
            {
                AspNetPager1.CurrentPageIndex = System.Convert.ToInt32(Request.QueryString["curpage"].Trim());
              
            }
            else
            {
                AspNetPager1.CurrentPageIndex = 1;
                
            }
        }
        private void ReapterDataBinding()
        {

            IList<CJJCH.Model.T_NET_MenuSecond> list = new List<CJJCH.Model.T_NET_MenuSecond>();
            list = bll_Second.GetMenu(3);
            rptStandards.DataSource = list;
            rptStandards.DataBind();
            int totalCount = 0;
            string keyword = "";
            if (lblKeyWord.Text != "")
            {
                keyword = LTP.Common.StringClass.EncodeUrl(lblKeyWord.Text.Trim());
            }
            int keytype = 0;
            if (lblKeyType.Text != "")
            {
                keytype = Convert.ToInt32(lblKeyType.Text.Trim());

            }
            int count = 0;
            if (lblHaveChild.Text == "True")
            {

                IList<CJJCH.Model.T_NET_News> model = new List<Model.T_NET_News>();
                if (lblSID.Text != "")
                {
                    model = bll_News.GetNewsList(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, Convert.ToInt32(lblSID.Text), keyword, keytype, "", "", ref totalCount, "");
                }
                else
                {
                    model = bll_News.GetNewsList(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, 10, keyword, keytype, "", "", ref totalCount, "");
                }
                count = model.Count;
                AspNetPager1.RecordCount = totalCount;
             
                rptNewsList.DataSource = model;
                rptNewsList.DataBind();
            }
            else
            {
                IList<CJJCH.Model.T_NET_News> model = new List<Model.T_NET_News>();
                if (lblSID.Text != "")
                {
                    model = bll_News.GetNewsList(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, Convert.ToInt32(lblSID.Text), keyword, keytype, "", "", ref totalCount, "");
                }
                else
                {
                    model = bll_News.GetNewsList(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, 3, keyword, keytype, "", "", ref totalCount, "");
                }
                count = model.Count;
                AspNetPager1.RecordCount = totalCount;
              
                rptNewsList.DataSource = model;
                rptNewsList.DataBind();
            }


            if (count == 0)
                litMessage.Text = "<table width=100%><tr style=height:18px bgcolor=#FFFFFF><td align='center'><font color=red>对不起，系统没有检索出有关信息！<font></td></tr></table>";
            else
                litMessage.Text = "";

            AspNetPager1.CustomInfoHTML = "共有：<font color=\"blue\"><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>条记录";
            AspNetPager1.CustomInfoHTML += " <font color=\"red\"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";
            AspNetPager1.CustomInfoHTML += "/<font color=\"blue\"><b>" + AspNetPager1.PageCount.ToString() + "</b></font>";
         
        }
        protected void rptStandards_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {

            ((HyperLink)e.Item.FindControl("lnkSubMenu")).Text = ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).MenuName;
            ((HyperLink)e.Item.FindControl("lnkSubMenu")).NavigateUrl = "TeachList.aspx?sid=" + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID
                + "&name=" + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).MenuName
                + "&HaveChild=" + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).HaveChild
                + "&MID=" + ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).MenuTypeID;

            if (((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID.ToString() == lblSID.Text.ToString())
            {
                ((System.Web.UI.HtmlControls.HtmlControl)e.Item.FindControl("divMenu")).Attributes.Add("class", "Header_TitleCur1");
                lblMenu.Text = ((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).MenuName;
                if (((CJJCH.Model.T_NET_MenuSecond)e.Item.DataItem).ID==8)
                {
                    div1.Style.Add("display", "none");
                    div2.Style.Add("display", "block");
                }
                else
                {
                   div1.Style.Add("display", "block");
                   div2.Style.Add("display", "none");
                }

            }
        }
        protected void rptNewsList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {

            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ((HyperLink)e.Item.FindControl("lnkStandards")).Text = LTP.Common.StringClass.GetENString(((CJJCH.Model.T_NET_News)e.Item.DataItem).DataTitle, 20);
                ((HyperLink)e.Item.FindControl("lnkStandards")).NavigateUrl = "StandardsDetails.aspx?ID="
                    + LTP.Common.StringClass.EncodeUrl(((CJJCH.Model.T_NET_News)e.Item.DataItem).ID.ToString())
                    + "&MID=" + LTP.Common.StringClass.EncodeUrl(lblMID.Text.Trim());
                ((Label)e.Item.FindControl("lblStandardsDate")).Text = ((CJJCH.Model.T_NET_News)e.Item.DataItem).PlusDate.ToString("yyyy/MM/dd");
            }
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            ReapterDataBinding();
  
        }
     

        protected void btnSave_Click(object sender, EventArgs e)
        {

        }
    }
}